using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace helicopterFight
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        public GraphicsDeviceManager graphics;
        public SpriteBatch spriteBatch;
        public TestState testState;
        public StateManager sm = null;
        public Network network;

        public static Console konsola = new Console();
        public static Controls sterowanie = new Controls();
        public static String stan = "MenuState";

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.IsFullScreen = false;
            graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0;
        }

        protected override void Initialize()
        {
            sm = new StateManager(this);

            testState = new TestState();
            sm.dodajStan(new MenuState());
            sm.dodajStan(testState);
            sm.dodajStan(new IngameMenuState());

            Components.Add(new GamerServicesComponent(this));       //Inicjalizacja sieci

            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            konsola.setFont(Content.Load<SpriteFont>("fonts/SpriteFont1"));
            konsola.setTraceString("Start", DateTime.Now.ToString());

            sm.wczytajDane();
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) && !stan.Equals("MenuState"))
            {
                sm.zmienStan("IngameMenu");
                stan = "IngameMenu";
                MenuState.gameMusic.Pause();
                MenuState.bgrMusic.Resume();
                if(TestState.heliCue.IsPlaying) 
                    TestState.heliCue.Pause();
            }   //this.Exit();

            sm.aktualizuj();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
            sm.rysuj(gameTime);
            konsola.draw(spriteBatch);
            base.Draw(gameTime);
        }
    }
}
